package seap.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import seap.beans.FornecedorServicoBean;
import seap.beans.ProdutoBean;
import seap.beans.TalhaoBean;
import seap.bo.LancarMadeiraCorteBO;
import seap.dao.FornecedorServicoDAO;
import seap.dao.ProdutoDAO;
import seap.dao.TalhaoDAO;

public class LancarMadeiraCorteAction extends DispatchAction {
	
    private Log logger = LogFactory.getLog(this.getClass());
	
    LancarMadeiraCorteBO bo = new LancarMadeiraCorteBO();
    
	public ActionForward cadastrar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    	logger.debug("Lancar Madeira Corte");
    	
    	String param1 = (String) request.getParameter("floresta");
    	String param2 = (String) request.getParameter("talhao");
    	String param3 = (String) request.getParameter("forn_serv");
    	String param4 = (String) request.getParameter("produto");
    	String param5 = (String) request.getParameter("quantidade");
    	String param6 = (String) request.getParameter("unidade_medida");
    	
    	int p2 = Integer.parseInt(param2);
    	int p3 = Integer.parseInt(param3);
    	int p4 = Integer.parseInt(param4);
    	String result = bo.add(param1,p2,p3,p4,param5,param6);
        
        return mapping.findForward(result);
    }
	
	public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    	
		TalhaoDAO tDAO = new TalhaoDAO();
		FornecedorServicoDAO fsDAO = new FornecedorServicoDAO();
		ProdutoDAO pDAO = new ProdutoDAO();
		
		List talhao = tDAO.localizarTodos(TalhaoBean.class);
		List fornServ = fsDAO.localizarTodos(FornecedorServicoBean.class);
		List prod = pDAO.localizarTodos(ProdutoBean.class);
		
		request.setAttribute("ListaTalhao", talhao);
		request.setAttribute("ListaFornServ", fornServ);
		request.setAttribute("ListaProd", prod);
		
        return mapping.findForward("sucesso");
    }
	
	public ActionForward buscar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    	logger.debug("");
        
        return null;
    }
}
